package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class IteratorDemo {
    public static void main(String[] args) {
        Collection<String> collection = new ArrayList<String>();
        collection.add("one");
        collection.add("#");
        collection.add("two");
        collection.add("#");
        collection.add("three");
        collection.add("#");
        collection.add("four");
        collection.add("#");
        collection.add("five");
        collection.add("#");
        collection.add("six");
        collection.add("#");
        collection.add("seven");
        System.out.println(collection);

        Iterator<String> it = collection.iterator();
        while (it.hasNext()){
            String str = it.next();
            if("#".equals(str)){
                it.remove();
            }
        }

        System.out.println(collection);
    }
}
